package com.lots.mapper;

import com.lots.domain.dto.LoginDto;
import com.lots.domain.entity.Dish;
import com.lots.domain.entity.User;
import com.lots.domain.entity.UserFavorite;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user where phone=#{phone} and password=#{password}")
    User login(LoginDto user);

    @Insert("insert into user(name,avatar,phone,password) values(#{name},#{avatar},#{phone},#{password})")
    void insert(User user);

    @Select("select * from user where phone=#{phone}")
    User selectByPhone(String phone);

    @Select("select dish_id from user_favorite where user_id = #{userId} order by create_time desc")
    List<Long> queryStars(Long userId);

    @Select("select * from user where id = #{userId}")
    User getUserById(Long userId);

    @Update("update user set name = #{name} where id = #{userId}")
    void updateUserName(Long userId, String name);
    @Update("update user set avatar = #{avatar} where id = #{userId}")
    void updateAvatar(Long userId, String avatar);
}
